/*
 * QStyleManager.h  0.4.0 / Nov 17, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#ifndef QSTYLEMANAGER_H
#define QSTYLEMANAGER_H

#include "Cute4jSwing.h"

#include "QFontSet.h"

// QStyleManager Class.  -------------------------------------------------------

/*!
 * \brief QStyle Manager.
 *
 * \author Slobodan Vrkacevic
 * \version 0.4.0
 */
class CUTE4J_EXPORT QStyleManager : public QObject
{
  Q_OBJECT
private:
  QStyleManager();
  ~QStyleManager();
public:
  const QString &systemStyleName() const;
  const QString &systemStyleDescription() const;
  QStringList &availableStyleNames();
  QStringList &availableThemeNames();
public slots:
  jboolean setStyle(JNIEnv *env, jstring name);
  void setTheme(JNIEnv *env, jobject colorPalette, jobject fontSet);
  void setUseSystemTheme(JNIEnv *env, jboolean useSystemTheme);
  void fillPalette(JNIEnv *env, jobject customColorPalette, jstring name);
  void fillPalette(JNIEnv *env, jobject customColorPalette, jint argb);
  void fillFontSet(JNIEnv *env, jobject customFontSet, jstring name);
public:
  static void initialize(JNIEnv *env, jclass systemColorPaletteClass,
                         jclass systemFontSetClass);
  static void setCustomProperty(const QString &name, const QString &value);
public:
  inline static QStyleManager *instance();
private:
  QStyle *createStyle(const QString &styleName);
  QPalette *getPalette(const QString &paletteName);
  QFontSet *getFontSet(const QString &fontSetName);
  QFontSet *getFontSet(JNIEnv *env, jobject fontSet);
  void fillPalette(JNIEnv *env, jobject customColorPalette, QPalette *palette);
  bool fillColor(JNIEnv *env, jobject customColorPalette, jfieldID fid,
                 QColor color);
  void loadPalette(JNIEnv *env, jobject colorPalette, QPalette *palette);
  void loadColor(JNIEnv *env, jobject customColorPalette, jmethodID metodID,
                 QPalette *palette, QPalette::ColorGroup cg,
                 QPalette::ColorRole cr);
  bool fillFont(JNIEnv *env, jobject customFontSet, jfieldID fid, QFont font);
  bool getFont(JNIEnv *env, QFont &result, jobject fontSet, jmethodID mid);
  bool initColorPaletteFIDs(JNIEnv *env, jclass cls);
  bool initColorPaletteMIDs(JNIEnv *env, jclass cls);
  bool initFontSetFIDs(JNIEnv *env, jclass cls);
  bool initFontSetMIDs(JNIEnv *env, jclass cls);
private:
  QString m_systemStyleName;
  QString m_systemStyleDescription;
  QStringList m_availableStyleNames;
  QStringList m_availableThemeNames;
  QPalette m_systemPallete;
  QFontSet m_systemFontSet;
  QHash<QString, QPalette *> m_palettes;
  QHash<QString, QFontSet *> m_fontSets;
  bool m_useSystemTheme;
  #ifdef Q_OS_WIN32
    bool m_winThemeable;
  #endif // Q_OS_WIN32
private:
  static QStyleManager *sm_instance;
  static jclass sm_systemColorPaletteClass;
  static jclass sm_systemFontSetClass;
  static jfieldID sm_systemColorPaletteNameFID;
  static jfieldID sm_systemFontSetNameFID;
  static jfieldID sm_activeBackgroundColorFID;
  static jfieldID sm_inactiveBackgroundColorFID;
  static jfieldID sm_disabledBackgroundColorFID;
  static jfieldID sm_activeForegroundColorFID;
  static jfieldID sm_inactiveForegroundColorFID;
  static jfieldID sm_disabledForegroundColorFID;
  static jfieldID sm_activeBaseColorFID;
  static jfieldID sm_inactiveBaseColorFID;
  static jfieldID sm_disabledBaseColorFID;
  static jfieldID sm_activeAlternateBaseColorFID;
  static jfieldID sm_inactiveAlternateBaseColorFID;
  static jfieldID sm_disabledAlternateBaseColorFID;
  static jfieldID sm_activeTextColorFID;
  static jfieldID sm_inactiveTextColorFID;
  static jfieldID sm_disabledTextColorFID;
  static jfieldID sm_activeButtonColorFID;
  static jfieldID sm_inactiveButtonColorFID;
  static jfieldID sm_disabledButtonColorFID;
  static jfieldID sm_activeButtonTextColorFID;
  static jfieldID sm_inactiveButtonTextColorFID;
  static jfieldID sm_disabledButtonTextColorFID;
  static jfieldID sm_activeBrightTextColorFID;
  static jfieldID sm_inactiveBrightTextColorFID;
  static jfieldID sm_disabledBrightTextColorFID;
  static jfieldID sm_activeLightColorFID;
  static jfieldID sm_inactiveLightColorFID;
  static jfieldID sm_disabledLightColorFID;
  static jfieldID sm_activeMidlightColorFID;
  static jfieldID sm_inactiveMidlightColorFID;
  static jfieldID sm_disabledMidlightColorFID;
  static jfieldID sm_activeDarkColorFID;
  static jfieldID sm_inactiveDarkColorFID;
  static jfieldID sm_disabledDarkColorFID;
  static jfieldID sm_activeMidColorFID;
  static jfieldID sm_inactiveMidColorFID;
  static jfieldID sm_disabledMidColorFID;
  static jfieldID sm_activeShadowColorFID;
  static jfieldID sm_inactiveShadowColorFID;
  static jfieldID sm_disabledShadowColorFID;
  static jfieldID sm_activeHighlightColorFID;
  static jfieldID sm_inactiveHighlightColorFID;
  static jfieldID sm_disabledHighlightColorFID;
  static jfieldID sm_activeHighlightedTextColorFID;
  static jfieldID sm_inactiveHighlightedTextColorFID;
  static jfieldID sm_disabledHighlightedTextColorFID;
  static jfieldID sm_activeLinkColorFID;
  static jfieldID sm_inactiveLinkColorFID;
  static jfieldID sm_disabledLinkColorFID;
  static jfieldID sm_activeLinkVisitedColorFID;
  static jfieldID sm_inactiveLinkVisitedColorFID;
  static jfieldID sm_disabledLinkVisitedColorFID;
  static jfieldID sm_defaultFontFID;
  static jfieldID sm_componentFontFID;
  static jfieldID sm_buttonFontFID;
  static jfieldID sm_menuFontFID;
  static jfieldID sm_menuBarFontFID;
  static jfieldID sm_textFontFID;
  static jfieldID sm_toolTipFontFID;
  static jmethodID sm_getActiveBackgroundColorMID;
  static jmethodID sm_getInactiveBackgroundColorMID;
  static jmethodID sm_getDisabledBackgroundColorMID;
  static jmethodID sm_getActiveForegroundColorMID;
  static jmethodID sm_getInactiveForegroundColorMID;
  static jmethodID sm_getDisabledForegroundColorMID;
  static jmethodID sm_getActiveBaseColorMID;
  static jmethodID sm_getInactiveBaseColorMID;
  static jmethodID sm_getDisabledBaseColorMID;
  static jmethodID sm_getActiveAlternateBaseColorMID;
  static jmethodID sm_getInactiveAlternateBaseColorMID;
  static jmethodID sm_getDisabledAlternateBaseColorMID;
  static jmethodID sm_getActiveTextColorMID;
  static jmethodID sm_getInactiveTextColorMID;
  static jmethodID sm_getDisabledTextColorMID;
  static jmethodID sm_getActiveButtonColorMID;
  static jmethodID sm_getInactiveButtonColorMID;
  static jmethodID sm_getDisabledButtonColorMID;
  static jmethodID sm_getActiveButtonTextColorMID;
  static jmethodID sm_getInactiveButtonTextColorMID;
  static jmethodID sm_getDisabledButtonTextColorMID;
  static jmethodID sm_getActiveBrightTextColorMID;
  static jmethodID sm_getInactiveBrightTextColorMID;
  static jmethodID sm_getDisabledBrightTextColorMID;
  static jmethodID sm_getActiveLightColorMID;
  static jmethodID sm_getInactiveLightColorMID;
  static jmethodID sm_getDisabledLightColorMID;
  static jmethodID sm_getActiveMidlightColorMID;
  static jmethodID sm_getInactiveMidlightColorMID;
  static jmethodID sm_getDisabledMidlightColorMID;
  static jmethodID sm_getActiveDarkColorMID;
  static jmethodID sm_getInactiveDarkColorMID;
  static jmethodID sm_getDisabledDarkColorMID;
  static jmethodID sm_getActiveMidColorMID;
  static jmethodID sm_getInactiveMidColorMID;
  static jmethodID sm_getDisabledMidColorMID;
  static jmethodID sm_getActiveShadowColorMID;
  static jmethodID sm_getInactiveShadowColorMID;
  static jmethodID sm_getDisabledShadowColorMID;
  static jmethodID sm_getActiveHighlightColorMID;
  static jmethodID sm_getInactiveHighlightColorMID;
  static jmethodID sm_getDisabledHighlightColorMID;
  static jmethodID sm_getActiveHighlightedTextColorMID;
  static jmethodID sm_getInactiveHighlightedTextColorMID;
  static jmethodID sm_getDisabledHighlightedTextColorMID;
  static jmethodID sm_getActiveLinkColorMID;
  static jmethodID sm_getInactiveLinkColorMID;
  static jmethodID sm_getDisabledLinkColorMID;
  static jmethodID sm_getActiveLinkVisitedColorMID;
  static jmethodID sm_getInactiveLinkVisitedColorMID;
  static jmethodID sm_getDisabledLinkVisitedColorMID;
  static jmethodID sm_getDefaultFontMID;
  static jmethodID sm_getComponentFontMID;
  static jmethodID sm_getFixedFontMID;
  static jmethodID sm_getButtonFontMID;
  static jmethodID sm_getMenuFontMID;
  static jmethodID sm_getMenuBarFontMID;
  static jmethodID sm_getTextFontMID;
  static jmethodID sm_getToolTipFontMID;
};

// QStyleManager :: Public Static Inline Member Function. ----------------------

/*!
 * \brief Returns QStyleManager instance.
 *
 * \return QStyleManager instance
 */
inline QStyleManager *QStyleManager::instance()
{
  return sm_instance;
}

// Macro Definition.  ----------------------------------------------------------

#define qStyleManager (QStyleManager::instance())

#endif // QSTYLEMANAGER_H
